<?php
/**
 * User: tridungpham
 * Date: 6/23/11
 * Time: 1:43 PM
 */
 
class EView extends View
{
    function __construct($viewName = NULL, $viewBlock = NULL)
    {
        parent::__construct($viewName,$viewBlock);
    }

    function renderBlock($blockName)
    {
        global $_app_config;
        if (isset($this->_block_data[$blockName]))
        {
            if (is_array($this->_block_data[$blockName]))
            {
                foreach ($this->_block_data[$blockName] as $key => $value)
                {
                    $$key = $value;
                }
            }
            else
            {
                $data = $this->_block_data[$blockName];
            }

        }
        else
        {
            $data = null;
        }

        if (is_null($this->_tplConfig['block'][$blockName][0]))
        {
            return $data;
        }
        else
        {
            if ($this->_tplConfig['block'][$blockName][1] == 'general')
            {
                $path = APP_PATH . 'templates' . DS . $this->_tplConfig['block'][$blockName][0];
            }
            else
            {
                $path = APP_PATH . 'components' . DS . $_app_config['component_name'] . DS . 'templates' . DS . $this->_tplConfig['block'][$blockName][0];
            }

            if (!file_exists($path))
            {
                exit("Cannot find template at $path");
            }
            ob_start();
            require $path;
            $output = ob_get_contents();
            ob_end_clean();
            return $output;
        }
    }

    public function render()
    {
        print_r($this->_tplConfig);exit;
    }
}
